import JSEncryptJS from './jsencrypt-js.js';
const RSA_PUBLIC_KEY = '-----BEGIN PUBLIC KEY-----\n' +
	'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDduO8bILPUOtX8xyIUoQIqRRm6\n' +
	'F/SXsA01JD8W97RGjrwICbE77wi7XHnDcTSSbvjOyysuiHGHqhTC3QSIZ1fpXeK6\n' +
	'RrtZphugZu+IGCY+INonwWE2HJselgFYsw/5XgyYSkUxBLgXmdqHfF22IXZyDSwO\n' +
	'VSyn4K5M35zE7u87MwIDAQAB\n' +
	'-----END PUBLIC KEY-----';
//特殊情况下会用到
const RSA_PRIVATE_KEY = '-----BEGIN RSA PRIVATE KEY-----\n' +
	'MIICXAIBAAKBgQDduO8bILPUOtX8xyIUoQIqRRm6F/SXsA01JD8W97RGjrwICbE7\n' +
	'7wi7XHnDcTSSbvjOyysuiHGHqhTC3QSIZ1fpXeK6RrtZphugZu+IGCY+INonwWE2\n' +
	'HJselgFYsw/5XgyYSkUxBLgXmdqHfF22IXZyDSwOVSyn4K5M35zE7u87MwIDAQAB\n' +
	'AoGAI/MSQbHBto17mKqo6fNZKIVfsH6l19phqdYgrJapEi+eaSc5J2CQZ+CMlZXL\n' +
	'UlrP2Ke0bq0My1RWXWn8jClFZXHJJpuWYbeaTIwyKpeoFQay/vKUMBh8utsz+KGG\n' +
	'6zrAtGDWNqI6RqK2cec59Qjut0UqImg7RG0HHGaR93hAjHECQQD62cOnKKEzM5Vj\n' +
	'mqI8JGsX+MlZ8+NO6xS9MXZrla+28qLmdo6BJAZL+ScRtpD5SmvVcWYxgp3Nn51x\n' +
	'CHPb3jDHAkEA4kYZWJMfavSp3N0kdEyvdM+xoKRVPpxAMyL04+SQDpoA6rUP4V7B\n' +
	'cKSaJgrtYw728kM4P3lbpHBRuOr/itnONQJBANYqr8l6fc5qHwRQFG0GpsxrovUC\n' +
	'rbJGMImqvjDyNngaxgu/csE9EYcxrDKKTVIZQOGVlKt2meXhfZjwn4I7PCcCQDBP\n' +
	'Fwo6HvMO2VU2QZoy5SLjVOEfNLPxWCOSywX8vmTfrGJv1bwgJtyNx/tnSddkUoTW\n' +
	'pSOoHVC2SjxYr8ZNSiECQGG5Jc7HGbe8VCVbHRg3eDiFJW6oSWZViYw5ue2DpyMN\n' +
	'CjIJkOuL8XmmW9lHUf+Dy1LFITHA1raTpugwsfqnW4o=\n' +
	'-----END RSA PRIVATE KEY-----';

function rsaEncode(str, publicKey) {
	let pubKey = publicKey || RSA_PUBLIC_KEY;
	let rsa = new JSEncryptJS(); // 创建加密对象实例	  
	rsa.setPublicKey(pubKey); //设置公钥
	return rsa.encrypt(str); // 对内容进行加密
}

function rsaDecode(str, privateKey) {
	let priKey = privateKey || RSA_PRIVATE_KEY;
	let rsa = new JSEncryptJS(); // 创建加密对象实例
	rsa.setPrivateKey(priKey); //设置私钥
	return rsa.decrypt(str);
}

export default {
	rsaEncode,
	rsaDecode
}
